package com.linght.SpringBoot;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * User:岁亮亮
 * Date:2024-11-05
 * TIME:15:55
 */
@RequestMapping("/request")
@RestController
public class RequestController {
   @RequestMapping("/hello")
    public String hell0(){

       return "Hello SpringMVC";
   }
   @RequestMapping("/hello1")
    public String hello1(){

       return "Hello SpringWebMVC";
   }

   @RequestMapping("/test1")
    public String test1(int integer){
       return "<h1>接收到的参数 </h1>";
   }
   @RequestMapping("/testInt")
    public String testint(int integer){
       return "接收到整数值是 " + integer;
   }
   @RequestMapping("/testInteger")
    public String testint(Integer integer){
       return "接收到整数值是 " + integer;
   }
   @RequestMapping("/student")
    public String student(Student student){
       return student.toString();
   }
   @RequestMapping("/string")
    public String string(String[] str){
       StringBuilder sb = new StringBuilder();
      for(String s:str){
          sb.append(s);
      }
      return sb.toString();
   }
   @RequestMapping("/List")
    public String string(@RequestParam List<String> list){

       return list.toString();
   }
   private ObjectMapper objectMapper = new ObjectMapper();
   @RequestMapping("/testJosn")
    public String testJosn(@RequestBody Student student) throws JsonProcessingException {
       String josn = "{\"classId\":1,\"username\":\"sll\"}";
       Student student1 = objectMapper.readValue(josn,Student.class);
       String josn2 = objectMapper.writeValueAsString(student1);
       return student.toString();
   }
   @RequestMapping("/josn")
    public String josn() throws JsonProcessingException {
      Student student = new Student();
      student.setUsername("sll");
      student.setClassId(1);
      student.setPassword("123");
      String josn = objectMapper.writeValueAsString(student);
      return josn;
   }


}
